package controller;

import service.Sub;
import extthread.MyThreadA;
import extthread.MyThreadB;


/**
　* @Description: TODO
　* @param ${tags}
　* @return ${return_type}
　* @throws
　* @author Merlin
　* @date 2018/6/21 19:00
　*/

/**
 * 同步不具有继承性
 */
public class Test {

	public static void main(String[] args) {
		Sub subRef = new Sub();

		MyThreadA a = new MyThreadA(subRef);
		a.setName("A");
		a.start();

		MyThreadB b = new MyThreadB(subRef);
		b.setName("B");
		b.start();
	}

	/**
	 * 当子类sub不加同步synchronized方法，可以看出同步不能继承。
	 * 输出结果：
	 * int sub 下一步sleep begin threadName=A time=1529578997026
	   int sub 下一步sleep begin threadName=B time=1529578997029
	   int sub 下一步sleep   end threadName=A time=1529579002027
	   int main 下一步sleep begin threadName=A time=1529579002027
	   int sub 下一步sleep   end threadName=B time=1529579002030
	   int main 下一步sleep   end threadName=A time=1529579007028
	   int main 下一步sleep begin threadName=B time=1529579007028
	   int main 下一步sleep   end threadName=B time=1529579012028
	 *
	 * 当子类sub添加同步synchronized方法
	 * 输出结果：
	 * int sub 下一步sleep begin threadName=A time=1529579170925
	   int sub 下一步sleep   end threadName=A time=1529579175926
	   int main 下一步sleep begin threadName=A time=1529579175926
	   int main 下一步sleep   end threadName=A time=1529579180926
	   int sub 下一步sleep begin threadName=B time=1529579180927
	   int sub 下一步sleep   end threadName=B time=1529579185927
	   int main 下一步sleep begin threadName=B time=1529579185927
	   int main 下一步sleep   end threadName=B time=1529579190928
	 *
	 */

}
